<?php
// Extension for Epicwin Plugin by Dameer, Sofarider
$this_file = str_replace( '\\', '/', __FILE__ );
$this_file = explode( 'wp-content', $this_file );
$this_file = $this_file[ 0 ];
require( $this_file . 'wp-blog-header.php' );

$response = '';
if( $_POST[ 'action' ] == 'subscribe' && wp_verify_nonce( $_POST[ 'sofa_suppastore_ccn' ], 'chck_ref_ccn' ) ) {
	
	if( empty( $_POST[ 'sub_name' ] ) ) $response .= '0x';
	else $sub_name = strip_tags( $_POST[ 'sub_name' ] );
	
	if( filter_input( INPUT_POST, 'sub_email', FILTER_VALIDATE_EMAIL ) ) $sub_email = $_POST[ 'sub_email' ];
	else $response .= '1x';
	
	if( $response != '' ) {
		echo $response;
	} else {
		$res = $wpdb->query( $wpdb->prepare( "SELECT email FROM epicwin_feed WHERE email='{$_POST['sub_email']}'" ) );
		if( $res > 0 ) {
			if( $wpdb->query( $wpdb->prepare( "UPDATE epicwin_feed SET opt_in=1 WHERE email='{$_POST['sub_email']}'" ) ) ) {
				echo $response .= '2x';
			} else {
				echo $response .= '3x';
			}
		}
		
		if( $wpdb->insert( 'epicwin_feed', array( 'email' => $sub_email, 'name' => $sub_name, 'opt_in' => 1 ), array( '%s', '%s', '%d' ) ) ) {
			echo $response .= '2x';
		}
	}
} else echo $response;